<template>
<div>
  <!--    面包屑导航区-->
  <el-breadcrumb separator-class="el-icon-arrow-right">
    <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
    <el-breadcrumb-item>订单管理</el-breadcrumb-item>
    <el-breadcrumb-item>订单列表</el-breadcrumb-item>
  </el-breadcrumb>

  <!--卡片视图区-->
  <el-card>
    <!--查询订单区-->
    <el-input placeholder="请输入内容" v-model="page.query" style="width: 400px">
      <el-button slot="append" icon="el-icon-search" @click="getOrdersData"></el-button>
    </el-input>
    <!--订单数据区 -->
    <el-table :data="ordersData" border stripe>
      <el-table-column type="index" label="#"></el-table-column>
      <el-table-column prop="order_number" label="用户名"></el-table-column>
      <el-table-column label="是否支付" v-slot="slot" width="100px">
        <el-tag type="danger" v-if="slot.row.pay_status==='0'">未付款</el-tag>
        <el-tag type="success" v-if="slot.row.pay_status!=='0'">未付款</el-tag>
      </el-table-column>
      <el-table-column prop="is_send" label="是否发货" width="100px"></el-table-column>
      <el-table-column label="下单时间" v-slot="slot">{{getTime(slot.row.update_time)}}</el-table-column>
      <el-table-column prop="order_price" label="价格" width="100px"></el-table-column>
      <el-table-column label="操作" v-slot="slot">
        <el-button circle type="primary" icon="el-icon-edit" @click="orderEdit"></el-button>
        <el-button circle type="success" icon="el-icon-s-promotion" @click="orderWatch(slot.row)"></el-button>
      </el-table-column>
    </el-table>
    <!--页码区-->
    <el-pagination
        @size-change="pageSizeChange"
        @current-change="pageCurrentChange"
        :current-page="page.pagenum"
        :page-sizes="[6, 7, 8, 10]"
        :page-size="page.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="page.total">
    </el-pagination>
  </el-card>

  <!--对话框区-->
  <div>
    <!--修改地址对话框-->
    <el-dialog title="修改地址" :visible.sync="isShowAddress" @close="closeAddressDialog">
      <!--表格区-->
      <el-form label-width="80px" :model="address" ref="form">
        <el-form-item label="省/市/区">
          <!--
          v-model="address"  :选中的值【数组，每一项就是value值】
          :options="cityData" ：数据源，我们渲染数据的来源
          :props  :配置项
          expandTrigger:'hover' ：悬浮触发子节点
          value:'value'  ：每一项对应的值【对应options每一项里面的】
          label:'label'  ：每一项展示出来的【对应options每一项里面的】
          -->
          <el-cascader
              style="width: 100%"
              v-model="address"
              :options="cityData"
              :props="{
                expandTrigger: 'hover' ,value:'value',label:'label'
              }"
          >
          </el-cascader>
        </el-form-item>
        <el-form-item label="详细地址">
          <el-input v-model="detailAddress"></el-input>
        </el-form-item>
      </el-form>
      <!--按钮区-->
      <span slot="footer" class="dialog-footer">
        <el-button type="info" @click="isShowAddress=false">取消</el-button>
        <el-button type="primary" @click="function (){$message.success('修改地址成功');isShowAddress=false}">确定</el-button>
      </span>
    </el-dialog>
    <!--展示物流进度的对话框-->
    <el-dialog title="物流进度" :visible.sync="isShowWL">
      <el-timeline >
        <el-timeline-item v-for="(item,index) in WL" :timestamp="item.ftime" :key="index">
            {{item.context}}
        </el-timeline-item>
      </el-timeline>
    </el-dialog>
  </div>
</div>
</template>

<script>
import moment from "moment";
import cityData from "./citydata";
export default {
  name: "Orders",
  data(){
    return{
      //页码
      page:{
        query:'',
        pagenum:1,
        pagesize:6,
        total:1
      },
      //订单数据
      ordersData:[],
      //展示修改地址对话框
      isShowAddress:false,
      //是否展示物流进度对话框
      isShowWL:false,
      //级联选择器选择地址
      address:[],
      //城市级联选择器数据
      cityData,
      //详细地址
      detailAddress:'',
      //物流数据
      WL:[]
    }
  },
  methods:{
    //获取订单数据
    getOrdersData(){
      this.$http.get('orders',{params:this.page}).then(res=>{
        if(res.data.meta.status!==200)return this.$message.error("获取列表失败")
        this.ordersData=res.data.data.goods
        this.page.total=res.data.data.total
        console.log('订单数据')
        console.log(this.ordersData)
      })
    },
    //页面大小发生变化
    pageSizeChange(val){
      this.page.pagesize=val
      this.getOrdersData()
    },
    //页号发生变化
    pageCurrentChange(val){
      this.page.pagenum=val
      this.getOrdersData()
    },
    //格式化时间
    getTime(time){
      return moment(time).format("Y/M/D h:m:s")
    },
    //编辑订单
    orderEdit(){
      this.isShowAddress=!this.isShowAddress
    },
    // 查看订单物流
    orderWatch(row){
      console.log(row)
      this.isShowWL=!this.isShowWL
      this.$http.get('/kuaidi/1106975712662').then(res=>{
        this.WL=res.data.data
        console.log('物流数据')
        console.log(res)
        console.log('WL')
        console.log(this.WL)
      })
    },
    //关闭修改地址对话框
    closeAddressDialog(){
      this.detailAddress=''
    },
  },
  created() {
    this.getOrdersData()
  }
}
</script>

<style scoped>

</style>